<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>修改联系人</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					var returnVal = true;
					
					var age = $("#age").val();
					var email = $("#email").val();
					var mobile = $("#mobile").val();
					var phone = $("#phone").val();
					var qq = $("#qq").val();
					var wechat = $("#wechat").val();
					//联系方式至少有一个
					if(email==""&&mobile==""&&phone==""&&qq==""&&wechat==""){
						alert("请至少填写一个联系方式");
						returnVal=false;
					}
					//清除错误信息
					if(age==""){
						$("#ageInfo").text("");
					}
					if(email==""){
						$("#emailInfo").text("");
					}
					if(phone==""){
						$("#phoneInfo").text("");
					}
					if(qq==""){
						$("#qqInfo").text("");
					}
					//验证手机号码
					var a = 0;
					var mobile2 = mobile.replace("，",",");
					if(mobile2!=""){
						var mobileList = mobile2.split(",");
						for(var i=0;i<mobileList.length;i++){
							if(!(/^1\d{10}$/.test(mobileList[i]))){
								$("#mobileInfo").text("格式不正确");
								a = 1;
								returnVal = false;
							}
						}
						if(a==0){
							$("#mobileInfo").text("*");
						}
					}
					//验证年龄
					var b = 0
					if(age!=""){
						if(!(/^(?:[1-9][0-9]?|1[01][0-9]|120)$/.test(age))){
							$("#ageInfo").text("格式不正确");
							b = 1;
							returnVal = false;
						}
						if(b==0){
							$("#ageInfo").text("");
						}
					}
					
					//验证邮箱
					var c = 0;
					var email2 = email.replace("，",",");
					if(email2!=""){
						var emailList = email2.split(",");
						for(var i=0;i<emailList.length;i++){
							if(!(/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/.test(emailList[i]))){
								$("#emailInfo").text("格式不正确");
								c = 1;
								returnVal = false;
							}
						}
						if(c==0){
							$("#emailInfo").text("");
						}
					}
					
					//验证座机
					var d = 0;
					var phone2 = phone.replace("，",",");
					if(phone2!=""){
						var phoneList = phone2.split(",");
						for(var i=0;i<phoneList.length;i++){
							if(!(/^0\d{2,3}-?\d{7,8}$/.test(phoneList[i]))){
								$("#phoneInfo").text("格式不正确:请填写区号和座机号");
								d = 1;
								returnVal = false;
							}
						}
						if(d==0){
							$("#phoneInfo").text("");
						}
					}
					
					//验证QQ
					var e = 0;
					var qq2 = qq.replace("，",",");
					if(qq2!=""){
						var qqList = qq2.split(",");
						for(var i=0;i<qqList.length;i++){
							if(!(/^\d{5,18}$/.test(qqList[i]))){
								$("#qqInfo").text("格式不正确");
								e = 1;
								returnVal = false;
							}
						}
						if(e==0){
							$("#qqInfo").text("");
						}
					}
					
					if(returnVal == false){
						return false;
					}else{
						if(mobile!=""){
							$.ajax({
								type:"get",
								url:"${ctx}/crm/business/hycrmContact/findMobile",
								data:"mobile="+mobile2,
								async:false,
								success:function(data){
									if(data=="true"){
										if(confirm("号码已存在,确定要添加吗？")){
											returnVal = true;
										}else{
											returnVal = false;
										}
									}
								}
							});
						}
					}
					
					if(returnVal==false){
						return false;
					}
					
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
	<style type="text/css">
		.input-xlarge{
			width:350px;
		}
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<%-- <li><a href="${ctx}/business/hycrmContact/">添加联系人列表</a></li> --%>
		<li class="active"><a href="javascript:void(0)">修改联系人</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="hycrmContact" action="${ctx}/crm/business/hycrmContact/save" method="post" class="form-horizontal">
		<form:hidden path="customerId"/>
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">姓名：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="64" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">性别：</label>
			<div class="controls">
				<form:select path="sex" htmlEscape="false" maxlength="64" class="input-xlarge">
					<option value="男">男</option>
					<option value="女">女</option>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">年龄：</label>
			<div class="controls">
				<form:input id="age" path="age" htmlEscape="false" maxlength="4" class="input-xlarge "/>
				<span class="help-inline"><font color="red" id="ageInfo"></font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">部门：</label>
			<div class="controls">
				<form:input path="dept" htmlEscape="false" maxlength="20" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">职位：</label>
			<div class="controls">
				<form:input path="post" htmlEscape="false" maxlength="20" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">职能：</label>
			<div class="controls">
				<form:input path="function" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">地址：</label>
			<div class="controls">
				<form:input path="address" htmlEscape="false" maxlength="100" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">注意：</label>
			<div class="controls">
				<p style="color:red;font-weight:bold;">添加多个相同联系方式的联系号码请用逗号隔开</p>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">邮箱：</label>
			<div class="controls">
				<form:input id="email" path="email" htmlEscape="false" maxlength="400" class="input-xlarge "/>
				<span class="help-inline"><font color="red" id="emailInfo"></font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">手机：</label>
			<div class="controls">
				<form:input id="mobile" path="mobile" htmlEscape="false" maxlength="500" class="input-xlarge"/>
				<span class="help-inline"><font color="red" id="mobileInfo"></font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">座机：</label>
			<div class="controls">
				<form:input id="phone" path="phone" htmlEscape="false" maxlength="500" class="input-xlarge "/>
				<span class="help-inline"><font color="red" id="phoneInfo"></font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">微信：</label>
			<div class="controls">
				<form:input id="wechat" path="wechat" htmlEscape="false" maxlength="300" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">QQ：</label>
			<div class="controls">
				<form:input id="qq" path="qq" htmlEscape="false" maxlength="300" class="input-xlarge "/>
				<span class="help-inline"><font color="red" id="qqInfo"></font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">其他：</label>
			<div class="controls">
				<form:input path="other" htmlEscape="false" maxlength="800" class="input-xlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>